
// 定义Person类
class Person {
    // 属性
    private String name;
    private int age;
    private String gender;
    private String occupation;
    private double salary;

    // 构造方法
    public Person() {
    }

    public Person(String name, int age, String gender, String occupation, double salary) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.occupation = occupation;
        this.salary = salary;
    }

    // 方法1: 获取个人信息
    public void getInfo() {
        System.out.println("姓名：" + this.name);
        System.out.println("年龄：" + this.age);
        System.out.println("性别：" + this.gender);
        System.out.println("职业：" + this.occupation);
        System.out.println("工资：" + this.salary);
    }

    // 方法2: 修改个人信息
    public void updateInfo(String name, int age, String gender, String occupation, double salary) {
        this.name = name;
        this.age = age;
        this.gender = gender;
        this.occupation = occupation;
        this.salary = salary;
    }

    // 方法3: 计算税后工资
    public double calculateAfterTaxSalary() {
        double taxRate = 0.2; // 假设税率为20%
        return this.salary * (1 - taxRate);
    }
}

// 定义Car类
class Car {
    // 属性
    private String brand;
    private String model;
    private int year;
    private String color;
    private double price;

    // 构造方法
    public Car() {
    }

    public Car(String brand, String model, int year, String color, double price) {
        this.brand = brand;
        this.model = model;
        this.year = year;
        this.color = color;
        this.price = price;
    }

    // 方法1: 获取车辆信息
    public void getInfo() {
        System.out.println("品牌：" + this.brand);
        System.out.println("型号：" + this.model);
        System.out.println("年份：" + this.year);
        System.out.println("颜色：" + this.color);
        System.out.println("价格：" + this.price);
    }

    // 方法2: 修改车辆价格
    public void updatePrice(double newPrice) {
        this.price = newPrice;
    }

    // 方法3: 判断车辆是否新车（5年内为新车）
    public boolean isNewCar() {
        int currentYear = 2023; // 假设当前年份为2023年
        return (currentYear - this.year) <= 5;
    }
}

// 主函数
public class Main {
    public static void main(String[] args) {
        // 创建两个Person对象
        Person person1 = new Person("张三", 25, "男", "工程师", 5000);
        Person person2 = new Person();
        person2.updateInfo("李四", 30, "女", "教师", 6000);

        // 调用Person类的方法
        System.out.println("-----个人信息-----");
        person1.getInfo();
        System.out.println("-----------------");

        System.out.println("税后工资：" + person2.calculateAfterTaxSalary());

        // 创建两个Car对象
        Car car1 = new Car("BMW", "X5", 2018, "黑色", 500000);
        Car car2 = new Car();
        car2.updatePrice(600000);

        // 调用Car类的方法
        System.out.println("--- --车辆信息-----");
        car1.getInfo();
        System.out.println("-----------------");

        System.out.println("是否新车：" + car2.isNewCar());
    }
}


